<html>
<body>
Calculator:
<form action="calculator.php" method="GET">
 <input type="text" name="calculate" />
<input type="submit" />
</form>
<?php
$equation = $_GET["calculate"];
if (preg_match("/[\-]?(([0-9]+[\.]?[0-9]*)|([0-9]*[\.]?[0-9]+))([\/\*\+\-][\-]?(([0-9]+[\.]?[0-9]*)|([0-9]*[\.]?[0-9]+)))*/", $equation, $matches))
{
  echo $matches[0] . "<br />";
    if($equation == $matches[0])
   {
if (preg_match ("/[\/](([0]+$)|([0]*[\.][0]*$)|([0]*[\.][0]*[^0-9]))/", $equation))

       echo "Invalid input expression: " . $equation;
     else
     {
       eval("\$ans = $equation ;");
       echo "Result: " . $equation . " = " . $ans;
     }
   }
  else
  {
    echo "Invalid input expression ".$equation."<br />";
  }
}
else
echo "Invalid input expression ".$equation."<br />";
?>
</body>
</html>